<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<title>采购订单新增</title>
		<link rel="stylesheet" type="text/css" href="css/public.css">
		<script language="JavaScript" src="js/public.js"></script>
		<script type="text/javascript" src="js/date1.js"></script>
		<script type="text/javascript" src="js/stockorder.js"></script>
		<script type="text/javascript" src="js/validate.js"></script>
		<script type="text/javascript" src="js/ajax.js"></script>	
		<script type="text/javascript"	src="js/date.js"></script>
		<script type="text/javascript">
			function validate(){
				//供应商名称
				var supplierName = document.getElementById('supplierName');
				//采购订单编号
				var code = document.getElementById('code');
				//币别名称
				var currencyName = document.getElementById('currencyName');
				//结算方式名称''
				var settlementName = document.getElementById('settlementName');
				//部门经理
				var managerName = document.getElementById('managerName');
				//部门名称
				var departmentName = document.getElementById('departmentName');
				//业务员名称
				var businesserName = document.getElementById('businesserName');
				//表格
				var mbody = document.getElementById('mbody');
				
				//验证供应商名称
				if(!isNotNull(supplierName,'供应商'))
					return false ;	
				//验证采购订单编号
				if(!isNotNull(code,'编号')||!f_check_number(code,'编号')||!f_check_NumLength(code,'编号'))
					return false ;
				//验证币别名称
				if(!isNotNull(currencyName,'币别'))
					return false ;	
				//验证结算方式名称
				if(!isNotNull(settlementName,'结算方式'))
					return false ;				
				//验证部门经理名称
				if(!isNotNull(managerName,'部门经理'))
					return false ;	
				//验证业务员名称
				if(!isNotNull(businesserName,'部门经理'))
					return false ;	
				
				if(mbody.rows.length<=0){
					alert("请添加明细");
					return false;			
				}
				else{
					for(var i=0;i<mbody.rows.length;i++){
						//代码
						var materialCode = document.getElementById('materialCode'+i);
						//计量单位
						var measureUnitName = document.getElementById('measureUnitName'+i);
						//数量
						var cost = document.getElementById('cost'+i);
						//单价
						var unitPrice = document.getElementById('unitPrice'+i);
						//含税单价
						var realTotalUnitPrice = document.getElementById('realTotalUnitPrice'+1);
						//金额
						var money = document.getElementById('money'+rowIndex);
						//折扣率
						var discount = document.getElementById('discount'+rowIndex);
						
						//折扣额
						var discountPrice = document.getElementById('discountPrice'+rowIndex);
						
						//税额
						var dutyPrice = document.getElementById('dutyPrice'+rowIndex);
						//税率
						var dutyFrank = document.getElementById('dutyFrank'+rowIndex);
						
						//价税合计
						var totalMoney = document.getElementById('totalMoney'+rowIndex);
						
						var rowIndex = i+1 ;
						//验证代码					
						if(!(isNotNull(materialCode,'第'+rowIndex+'行:'+'物料代码')&&f_check_ZhOrNumOrLett(materialCode,'第'+rowIndex+'行:'+'物料代码')))
							return false;
						//单位
						if(!(isNotNull(measureUnitName,'第'+rowIndex+'行:'+'单位')&&f_check_ZhOrNumOrLett(measureUnitName,'第'+rowIndex+'行:'+'单位')))
							return false;
						//数量
						if(!(isNotNull(cost,'第'+rowIndex+'行:'+'数量')&&f_check_float(cost,'第'+rowIndex+'行:'+'数量')))
							return false;
						//单价
						if(!(isNotNull(unitPrice,'第'+rowIndex+'行:'+'单价')&&f_check_float(unitPrice,'第'+rowIndex+'行:'+'单价')))
							return false;
						//含税单价
						if(!(isNotNull(realTotalUnitPrice,'第'+rowIndex+'行:'+'实际含税单价')&&f_check_float(realTotalUnitPrice,'第'+rowIndex+'行:'+'实际含税单价')))
							return false;
						//金额
						if(!(isNotNull(money,'第'+rowIndex+'行:'+'金额')&&f_check_float(money,'第'+rowIndex+'行:'+'金额')))
							return false;
						
						//折扣率		
						if(!(isNotNull(discount,'第'+rowIndex+'行:'+'折扣率')&&f_check_float(discount,'第'+rowIndex+'行:'+'折扣率')))
							return false;
						//折扣额	
						if(!(isNotNull(discountPrice,'第'+rowIndex+'行:'+'折扣额')&&f_check_float(discountPrice,'第'+rowIndex+'行:'+'折扣额')))
							return false;
						//税额	
						if(!(isNotNull(dutyPrice,'第'+rowIndex+'行:'+'税额')&&f_check_float(dutyPrice,'第'+rowIndex+'行:'+'税额')))
							return false;
						//稅率
						if(!(isNotNull(dutyFrank,'第'+rowIndex+'行:'+'稅率')&&f_check_float(dutyFrank,'第'+rowIndex+'行:'+'稅率')))
							return false;
							
					}				
				}
			}
		
		</script>		
	</head>
<body>
	<div id="info_all">
		<div id="info_top"> 
			采购订单新增 
		</div>
		<!-- 主输入区 -->
		<!-- 功能按钮 -->
		<s:form action="addStockOrder.action" method="post" theme="simple" cssClass="submitForm" onsubmit=" return validate()">
		<div id="info_main">
			<!-- 查询栏 -->
			<div id="info_input">
				<hr>
				<table>
					<tr>
						<td width="60px">
							供应商*
						</td>
						<td width="130px">	
							<s:hidden name="stockOrderModel.supplierId" id="supplierId"></s:hidden>
							<s:textfield name="" size="12" id="supplierName" id="supplierName" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand" onclick="openWin('supplierSelect.action','supplier',750,700,0)">
						</td>
						<td width="50px">
							日期*
						</td>
						<td width="130px">
							<s:textfield name="stockOrderModel.builtTime" size="12"  readonly="true" cssStyle="cursor:hand" onclick="calendar.setHook(this)"></s:textfield>
							
						</td>
						<td width="55px">
							编号
						</td>
						<td width="130px">
							<s:textfield name="stockOrderModel.stockCode" size="12" id="code"></s:textfield>
						</td>
						<td width="74px">
							采购方式*
						</td>
						<td width="130px">
							<s:select list="#{'1':'现购','2':'赊购'}" name="stockOrderModel.stockWay" cssStyle="width:107px"></s:select>
						</td>

						<td width="55px">
							币别*
						</td>
						<td width="130px">
							<s:hidden name="stockOrderModel.currencyId" id="currencyId" value="111"></s:hidden>
							<s:textfield name="" id="currencyName" size="12" readonly="true" value="人民币"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="openWin('selectCurrency.action','currency',750,700,0)">
						</td>
					</tr>
					<tr>
						<td>
							结算方式
						</td>
						<td>
							<s:hidden name="stockOrderModel.settlementId" id="settlementId"></s:hidden>
							<s:textfield name="" id="settlementName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="openWin('selectSettlement.action','settlement',750,700,0)">
						</td>
					
						<td>
							结算日期
						</td>
						<td>
							<s:textfield name="stockOrderModel.balanceDate" size="12"  readonly="true" cssStyle="cursor:hand" onclick="calendar.setHook(this)"></s:textfield>
						</td>
						
						<td>
							摘要
						</td>
						<td colspan="3">
							<s:textfield name="stockOrderModel.remark" size="47"></s:textfield>
											</td>
						<td>
							汇率*
						</td>
						<td>
							<s:textfield id="rate" readonly="true" size="12" value="1.000000"></s:textfield>
						</td>
					</tr>
					<tr>
						<td>
							主管
						</td>
						<td>
							<s:hidden id="candiateId"></s:hidden>
							<s:hidden id="candiateName"></s:hidden>
							<s:hidden name="stockOrderModel.managerId" id="managerId"></s:hidden>
							<s:textfield name="" id="managerName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="multiSelect2('candiateName','candiateId','managerName','managerId','selectMultiCandiate.action','candiate',700,800,0)">
						</td>
					
						<td>
							部门
						</td>
						<td>
							<s:hidden name="stockOrderModel.departmentId" id="departmentId"></s:hidden>
							<s:textfield name="" id="departmentName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="openWin('selectDepartment.action','department',500,600,0)">
						</td>
						<td>
							业务员
						</td>
						<td>
							<s:hidden name="stockOrderModel.businesserId" id="busnisserId"></s:hidden>
							<s:textfield name="" id="businesserName" size="12" readonly="true"></s:textfield>
							<img src="images/kookup.gif" style="cursor:hand"  onclick="multiSelect2('candiateName','candiateId','businesserName','busnisserId','selectMultiCandiate.action','candiate',500,600,0)">
						</td>
						
					</tr>
				</table>
				<hr>

			</div>
			<div class="sele" style="text-align: left; padding-left: 10px;">
				<input type="button" value="新增" onClick="addMaterialToStockOrder()"
					onfocus="this.blur()" onMouseOver="this.className='btnover'"
					onmouseout="this.className='btnout'" class="btnsize" />
				<input type="button" value="删除" onClick="delrow()"
					onFocus="this.blur()" onMouseOver="this.className='btnover'"
					onmouseout="this.className='btnout'" class="btnsize" />
				<hr>
			</div>
			<!-- 信息显示栏 -->
			<div id="info_info4">
				<table id="info_table" width="1820px" cellspacing=1px
					cellpadding=1px class="sortable">
					<thead id="head">
						<tr>
							<th>
								<input type="checkbox" name="checkbox" onClick="selectAll()" />
							</th>
							<th width="110px">
								物料代码(*)
							</th>
							<th width="120px">
								物料名称
							</th>
							<th>
								规格型号
							</th>
							
							<th width="120px">
								基本单位名称
							</th>
							<th width="120px">
								基本单位数量
							</th>
							<th width="90px">
								单位(*)
							</th>
							<th width="80px">
								数量
							</th>
							<th width="80px">
								单价
							</th>
							<th width="90px">
								含税单价
							</th>
							<th width="80px">
								金额
							</th>
							<th width="80px">
								折扣率
							</th>
							<th width="120px">
								实际含税单价
							</th>
							<th width="80px">
								折扣额
							</th>
							<th width="80px">
								税率(%)
							</th>
							<th width="80px">
								税额
							</th>
							<th width="80px">
								价税合计
							</th>
							<th width="120px">
								交货日期(*)
							</th>
							<th width="140px">
								备注
							</th>
						</tr>
					</thead>
					<tbody id="mbody">
						
					</tbody>
					<tfoot>
						<tr>
						</tr>
					</tfoot>
				</table>
				<script language="javascript">  
						//("表格名称","奇数行背景","偶数行背景","点击后背景");
						 mouseclick("info_table","#ffffff","#ffffff","#e6f0fd");
						 //("表格名称","奇数行背景","偶数行背景");
						 //setcolor("t","#ffffff","#ffffff");
				</script>
			</div>
			<div style="margin: 6px; text-align: center;">
				<input type="submit" value="保存"
					onFocus="this.blur()" onMouseOver="this.className='btnover'"
					onmouseout="this.className='btnout'" class="btnsize" />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" value="返回" onClick=""
				onFocus="this.blur()" onMouseOver="this.className='btnover'"
				onmouseout="this.className='btnout'" class="btnsize" />
			</div>
		</div>
		</s:form>
	</div>
</body>
</html>
							
